package com.helloags;

import java.io.IOException;

import org.dom4j.DocumentException;

import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IPermissionsAdmin2;
import com.esri.arcgis.server.IPermissionsAdmin2Proxy;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.ServerInitializer;

public class ChangePermission {
	public static void main(String[] args) throws AutomationException,
			IOException, DocumentException {
		ServerInitializer si = new ServerInitializer();
		// si.initializeServer("*", "zhushijie", "zsj123456");
		si.initializeServer("*", "administrator", "111111");

		ServerConnection conn = new ServerConnection();
		conn.connect("192.168.3.105");
		// conn.connect("192.168.3.107", "*", "arcgismanager", "123456");
//		IServerObjectAdmin2 soa = new IServerObjectAdmin2Proxy(conn.getServerObjectAdmin());
		IPermissionsAdmin2 soa = new IPermissionsAdmin2Proxy(conn.getServerObjectAdmin());
//		IEnumBSTR ebstr = soa.getAllPrincipals();
//		String bstr = ebstr.next();
		soa.allowPermission("zhu", "World.MapServer", "*");
//		soa.allowPermission("usa", "brazil.MapServer", "*");
//		soa.allowPermission("hi", "usa.MapServer", "*");
//		while(bstr.length() > 0){
//			System.out.print(bstr);
//			bstr = ebstr.next();
//			System.out.println();
//		}
//		soa.allowPermission(arg0, arg1, "*");
//		soa.cleanPermissions("hi");
		conn.release();
		
		System.out.println("Congratulaction!");
	}
}
